package com.flyou.ccnucenter.ui.frgment;


import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.flyou.ccnucenter.Constant;
import com.flyou.ccnucenter.R;
import com.flyou.ccnucenter.ui.frgment.Departments.FaFragment;
import com.flyou.ccnucenter.ui.frgment.Departments.GuoJiFragment;
import com.flyou.ccnucenter.ui.frgment.Departments.HuaXueFragment;
import com.flyou.ccnucenter.ui.frgment.Departments.HuanJingFragment;
import com.flyou.ccnucenter.ui.frgment.Departments.JYXXFragment;
import com.flyou.ccnucenter.ui.frgment.Departments.JiSuanJiFragment;
import com.flyou.ccnucenter.ui.frgment.Departments.JiaoKeYuanFragment;
import com.flyou.ccnucenter.ui.frgment.Departments.LiShiFragment;
import com.flyou.ccnucenter.ui.frgment.Departments.MusicFragment;
import com.flyou.ccnucenter.ui.frgment.Departments.ShangFragment;
import com.flyou.ccnucenter.ui.frgment.Departments.SheHuiFragment;
import com.flyou.ccnucenter.ui.frgment.Departments.ShengMingFragment;
import com.flyou.ccnucenter.ui.frgment.Departments.ShuXueFragment;
import com.flyou.ccnucenter.ui.frgment.Departments.WaiYuFragment;
import com.flyou.ccnucenter.ui.frgment.Departments.WenXueFragment;
import com.flyou.ccnucenter.ui.frgment.Departments.WuLiFragment;
import com.flyou.ccnucenter.ui.frgment.Departments.XinLiFragment;
import com.flyou.ccnucenter.ui.frgment.Departments.XinWenFragment;
import com.flyou.ccnucenter.ui.frgment.Departments.XinXiFragment;
import com.flyou.ccnucenter.ui.frgment.Departments.ZheXueFragment;
import com.flyou.ccnucenter.ui.frgment.Departments.ZhengZhiFragment;
import com.ogaclejapan.smarttablayout.SmartTabLayout;
import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItemAdapter;
import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItems;

import org.simple.eventbus.EventBus;

/**
 * MyUser: flyou
 * Date: 13-12-22
 * Time: 下午1:31
 * Mail: fangjaylong@gmail.com
 */
public class DepartmentNewFragment extends BaseFragment {
    private View mParentView;
    private SmartTabLayout mTabLayout;
    private ViewPager mViewPager;


    @Override
    protected View onCreatView(LayoutInflater inflater, ViewGroup container) {
        mParentView=inflater.inflate(R.layout.department_news, container, false);
        return mParentView;
    }

    @Override
    protected void initData() {

        FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(
                getChildFragmentManager(), FragmentPagerItems.with(context)
                .add(getString(R.string.wuli), WuLiFragment.class)
                .add(getString(R.string.lishi), LiShiFragment.class)
                .add(getString(R.string.zhexue), ZheXueFragment.class)
                .add(getString(R.string.waiyu), WaiYuFragment.class)
                .add(getString(R.string.huanjing), HuanJingFragment.class)
                .add(getString(R.string.shengming), ShengMingFragment.class)
//                .add(getString(R.string.makesi), MaKeSiFragment.class)
                .add(getString(R.string.jiaoyu), JiaoKeYuanFragment.class)

                .add(getString(R.string.zhengzhi), ZhengZhiFragment.class)
                .add(getString(R.string.shehui), SheHuiFragment.class)
                .add(getString(R.string.xinli), XinLiFragment.class)
                .add(getString(R.string.shuxue), ShuXueFragment.class)
                .add(getString(R.string.huaxue), HuaXueFragment.class)
                .add(getString(R.string.shangxue),ShangFragment.class)
                .add(getString(R.string.wenxue), WenXueFragment.class)
                .add(getString(R.string.guoji), GuoJiFragment.class)
                .add(getString(R.string.jsuanji), JiSuanJiFragment.class)
                .add(getString(R.string.xinwen), XinWenFragment.class)
                .add(getString(R.string.xinxi), XinXiFragment.class)
                .add(getString(R.string.music), MusicFragment.class)
                .add(getString(R.string.faxue), FaFragment.class)
                .add(getString(R.string.jyxx), JYXXFragment.class)

//                .add(getString(R.string.yaoxue), YaoXueFragment.class)
//                .add(getString(R.string.yixue), YiXueFragment.class)






                .create());
//mViewPager.setOffscreenPageLimit(10);
            if(mViewPager.getAdapter() == null) {
                mViewPager.setAdapter(adapter);
        }
        mTabLayout.setViewPager(mViewPager);
        mTabLayout.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener(){
            @Override
            public void onPageSelected(int position) {
                if (position>0) {
                    EventBus.getDefault().post("", Constant.DISABLE_MENU);
                }
                else {
                    EventBus.getDefault().post("", Constant.ENABLE_MENU);
                }
                super.onPageSelected(position);
            }
        });
    }

    @Override
    protected void initView() {
        mTabLayout= (SmartTabLayout) mParentView.findViewById(R.id.viewpagertab);
        mViewPager= (ViewPager) mParentView.findViewById(R.id.viewpager);
    }

    @Override
    public void onDestroy() {
        Log.d("DepartmentNewFragment", "onDestroy");
        EventBus.getDefault().post("", Constant.ENABLE_MENU);
        super.onDestroy();


    }

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        Log.d("DepartmentNewFragment", "onCreate");
    }
}
